package mulMan.gui.view;

import java.util.Observable;
import java.util.Observer;
import java.util.Set;

import javax.swing.table.DefaultTableModel;

import mulMan.domain.AudioFile;

public class AudioFileTableModel extends DefaultTableModel implements Observer{
	
	private static final long serialVersionUID = 4088093580510360926L;

	public AudioFileTableModel(Set<AudioFile> audioFileModels) {
		super();
		
		String[] tableHeader = {"Title", "Artist", "Album", "Length"};
		setColumnIdentifiers(tableHeader);
		for (AudioFile iterator : audioFileModels) {
			addElement(iterator);
		}
	}
	
	public void addElement(AudioFile element) {
		
		String[] data = new String[4];
		
		data[0] = element.getTitle();
		data[1] = element.getArtist();
		data[2] = element.getAlbum();
		data[3] = String.valueOf(element.getLength());
		
		addRow(data);
		((Observable) element).addObserver(this);
	}
	
	@Override
	public boolean isCellEditable(int rowIndex, int mColIndex) {
        return false;
	}

	public void update(Observable arg0, Object arg1) {
		//Observe the list to make all the updates directly here:
		//NewRow, DeleteRow, UpdateRow and not in the view.
		//Same for Playlist.
		//In that case, is this class, and the one of playlist usefull? Or at least, would the observer and update of the view be sufficient?
		
		//Also check in the controllers of audio file to call the getters 
		//and setters of the model (not directly the mapped class)
	}
}
